package com.cwf.common.utils.auth;

import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

@Slf4j
public class JasyptUtils {


    private static String key = "hello";


    public static String encrypt(String s) {
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(key); //设置盐值
        String encryptorResult = encryptor.encrypt(s);
        return encryptorResult;
    }

    public static String decrypt(String encryptorResult) {
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(key); //设置盐值
        try {
            String decryptResult = encryptor.decrypt(encryptorResult);
            return decryptResult;
        }catch (Exception e){
            return null;
        }

    }

}

